package com.hzdp.netty.bio.pool;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

import com.hzdp.netty.bio.TimeServerHandler;

public class TimeServer {
	public static void main(String[] args) {
		int port = 8080;
		ServerSocket serverSocket = null;

		try {
			serverSocket = new ServerSocket(port);
			System.out.println("The time server is started in port " + port);

			TimeServerHandlerExecutePool pool = new TimeServerHandlerExecutePool(50, 1000);
			while (true) {
				Socket socket = serverSocket.accept();
				pool.execute(new TimeServerHandler(socket));
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (serverSocket != null) {
				try {
					serverSocket.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
				serverSocket = null;
			}
		}

	}
}
